//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    tempFilePaths: ''
  },
  onLoad: function () {
  },
  chooseimage: function () {
    var that = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#CED63A",
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            that.chooseWxImage('album')
          } else if (res.tapIndex == 1) {
            that.chooseWxImage('camera')

          }

        }

      }
    })

  },

  chooseWxImage: function (type) {
    var that = this;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: function (res) {
        var tempFilePaths = res.tempFilePaths    
        wx.uploadFile({        
          url: 'https://www.songxiaohui.club/easyprice/shop/query', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
            'user': 'test'
          },
          success: function (res) {
            var data = JSON.parse(res.data);
            console.log(data.data);
            if (data.data != null) { 
              wx.setStorageSync('array', data.data);
              wx.navigateTo({
                url: '../detail/detail',

                success: function (res) {                 
                  console.log(res)
                },

                fail: function (err) {
                  console.log(err)
                }
              })

            }




          },

           fail: function (err) {
            console.log(err)
          }


        })

      }
    })
  }


}) 